home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / gifsave.zip / gifsave.doc < prev    next >
Text File  |  1992-09-26  |  11KB  |  363 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.                                       G I F S A V E
  18.  
  19.  
  20.                          C-functions to save an image using GIF
  21.  
  22.  
  23.  
  24.  
  25.                                   Written 26/9-1992 by
  26.  
  27.                                     Sverre H. Huseby
  28.                                      Bjoelsengt. 17
  29.                                        N-0468 Oslo
  30.                                          Norway
  31.  
  32.                                    Phone: +47 2 230539
  33.  
  34.                                    sverrehu@ifi.uio.no
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.           GIFSAVE reference                                       PAGE 2
  45.  
  46.  
  47.  
  48.  
  49.                                       INTRODUCTION
  50.                                       ============
  51.  
  52.  
  53.           The GIFSAVE functions (hereafter called GIFSAVE) make it possible 
  54.           to save GIF-images from your own graphic-producing C-programs.
  55.  
  56.               The Graphics Interchange Format(c) is the Copyright property of 
  57.               CompuServe Incorporated. GIF(tm) is a Service Mark property of 
  58.               CompuServe Incorporated. 
  59.  
  60.           (According to CompuServe Inc, the above note must be included in 
  61.           documentation of programs using GIF-files.)
  62.  
  63.           GIFSAVE creates simple GIF-files following the GIF87a standard. 
  64.           Interlaced images can not be created, and there should only be one 
  65.           image pr file.
  66.  
  67.           GIFSAVE is hereby dedicated to the Public Domain. Feel free to 
  68.           change the source code as you wish !!!
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.           GIFSAVE reference                                       PAGE 3
  80.  
  81.  
  82.  
  83.  
  84.                                       USING GIFSAVE
  85.                                       =============
  86.  
  87.  
  88.           GIFSAVE consists of four functions, all decleared in GIFSAVE.H:
  89.  
  90.               GIF_Create() creates new GIF-files. It takes parameters 
  91.                   specifying the filename, screen size, number of colors, and 
  92.                   color resolution. 
  93.  
  94.               GIF_SetColor() sets up the red, green and blue color 
  95.                   components. It should be called once for each possible 
  96.                   color. 
  97.  
  98.               GIF_CompressImage() performs the compression of the image. It 
  99.                   accepts parameters describing the position and size of the 
  100.                   image on screen, and a user defined callback function that 
  101.                   is supposed to fetch the pixel values. 
  102.  
  103.               GIF_Close() terminates and closes the file. 
  104.  
  105.           The functions should be called in the listed order for each 
  106.           GIF-file. One file must be closed before a new one can be created.
  107.  
  108.  
  109.           To use these functions, you must create a callback function that 
  110.           will do what is needed to get the pixel values for each point in 
  111.           the image.
  112.  
  113.  
  114.  
  115.  
  116.  
  117.                                        PORTABILITY
  118.                                        ===========
  119.  
  120.  
  121.           GIFSAVE is written using streams only, and all word (16 bits) 
  122.           outputs are split into byte outputs to force the byte swapping 
  123.           required in GIF-files. This should make the functions rather 
  124.           portable.
  125.  
  126.           File output is done through the functions Create(), Write(), 
  127.           WriteByte(), WriteWord() and Close(). If you want to rewrite 
  128.           GIFSAVE to use other file I/O than streams, you need only change 
  129.           theese functions.
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.           GIFSAVE reference                                       PAGE 4
  141.  
  142.  
  143.  
  144.  
  145.                                       THE FUNCTIONS
  146.                                       =============
  147.  
  148.  
  149.           GIF_Create() 
  150.  
  151.                   Function  Creates a new GIF-file, and stores info on the 
  152.                             screen. 
  153.  
  154.                     Syntax  int GIF_Create(
  155.                                     char *filename,
  156.                                     int width, int height,
  157.                                     int numcolors, int colorres
  158.                                 ); 
  159.  
  160.                    Remarks  Creates a new (or overwrites an existing) 
  161.                             GIF-file with the given filename. No 
  162.                             .GIF-extension is added.
  163.  
  164.                             The width- and height- parameters specifies the 
  165.                             size of the screen.
  166.  
  167.                             numcolors is the number of colors used in the 
  168.                             image.
  169.  
  170.                             colorres is number of bits used to encode a 
  171.                             primary color (red, green or blue). In GIF-files, 
  172.                             colors are built by combining given amounts of 
  173.                             each primary color. On VGA-cards, each color is 
  174.                             built by combining red, green and blue values in 
  175.                             the range [0, 63]. Encoding the number 63 would 
  176.                             require 6 bits, so colorres would be set to 6. 
  177.  
  178.               Return value  GIF_OK        - OK
  179.                             GIF_ERRCREATE - Error creating file
  180.                             GIF_ERRWRITE  - Error writing to file
  181.                             GIF_OUTMEM    - Out of memory
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.           GIFSAVE reference                                       PAGE 5
  194.  
  195.  
  196.  
  197.  
  198.           GIF_SetColor() 
  199.  
  200.                   Function  Specifies the primary color component of a color 
  201.                             used in the image. 
  202.  
  203.                     Syntax  void GIF_SetColor(
  204.                                      int colornum,
  205.                                      int red, int green, int blue
  206.                                  ); 
  207.  
  208.                    Remarks  This function updates the colortable-values for 
  209.                             color number colornum in the image.
  210.  
  211.                             Should be called for each color in the range
  212.  
  213.                                 [0, numcolors]
  214.  
  215.                             with red, green and blue components in the range
  216.  
  217.                                 [0, (1 << colorres) - 1]
  218.  
  219.                             colorres and colornum are values previousely 
  220.                             given to the function GIF_Create(). 
  221.  
  222.               Return value  None 
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.           GIFSAVE reference                                       PAGE 6
  234.  
  235.  
  236.  
  237.  
  238.           GIF_CompressImage() 
  239.  
  240.                   Function  Compresses an image and stores it in the current 
  241.                             file. 
  242.  
  243.                     Syntax  int GIF_CompressImage(
  244.                                     int left, int top,
  245.                                     int width, int height,
  246.                                     int (*getpixel)(int x, int y)
  247.                                 ); 
  248.  
  249.                    Remarks  The left- and top- parameters indicate the image 
  250.                             offset from the upper left corner of the screen. 
  251.                             They also give the start values for calls to the 
  252.                             userdefined callback function.
  253.  
  254.                             width and height give the size of the image. A 
  255.                             value of -1 indicates the equivalent screen size 
  256.                             given in the call to GIF_Create().
  257.  
  258.                             If the image is supposed to cover the entire 
  259.                             screen, values 0, 0, -1, -1 should be given.
  260.  
  261.                             GIF_CompressImage() obtains the pixel values by 
  262.                             calling a user specified function. This function 
  263.                             is passed in the parameter getpixel. See "THE 
  264.                             CALLBACK FUNCTION" further down for a description 
  265.                             of this function. 
  266.  
  267.               Return value  GIF_OK        - OK
  268.                             GIF_ERRWRITE  - Error writing to file
  269.                             GIF_OUTMEM    - Out of memory
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.           GIFSAVE ref